home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / FlyPaper.sit / Fly Paper / FlyPaper Source / App Sources / Thumbnail.cpp < prev    next >
C/C++ Source or Header  |  1996-06-22  |  2KB  |  91 lines

  1. #include "ST_MacClasses.h"
  2.  
  3. #ifndef THUMBNAIL_H
  4. #include "Thumbnail.h"
  5. #endif
  6.  
  7. #ifndef CLIPPINGFILE_H
  8. #include "ClippingFile.h"
  9. #endif
  10.  
  11. #ifndef FLYPAPERUTILS_H
  12. #include "FlyPaperUtils.h"
  13. #endif
  14.  
  15. #define                        kDictionaryResType            'Info'
  16. #define                        kDictionaryResID            128
  17.  
  18. class CGenericThumbnail : public CThumbnail
  19. {
  20. public:
  21.                         CGenericThumbnail (CClippingFile* file, FlavorType primaryFlavor);
  22.                         ~CGenericThumbnail ();
  23.  
  24.     virtual void        Draw (Rect& r);
  25.     
  26. private:
  27.     unsigned char        fName [32];
  28. };
  29.  
  30. CThumbnail::CThumbnail (CClippingFile* file) :
  31.     fFile (file)
  32. {
  33. }
  34.  
  35. CThumbnail::~CThumbnail ()
  36. {
  37. }
  38.  
  39. CThumbnail*    CThumbnail::NewThumbnail (CClippingFile* file, Rect& bounds)
  40. {
  41.     FlavorType        flavor;
  42.     file -> GetIndFlavorType (1, flavor);
  43.     return new CGenericThumbnail (file, flavor);
  44. }
  45.  
  46. CGenericThumbnail::CGenericThumbnail (CClippingFile* file, FlavorType primaryFlavor) :
  47.     CThumbnail (file)
  48. {
  49.     Handle                dictionary;
  50.     short                count;
  51.     
  52.     dictionary = Get1Resource (kDictionaryResType, kDictionaryResID);
  53.     if (!dictionary)
  54.         throw resNotFound;
  55.     
  56.     count = **((short**)dictionary);
  57.     FlavorType*            f = (FlavorType*) (*dictionary + sizeof (short));
  58.     unsigned char*        s = ((unsigned char*)f) + 4;
  59.     Boolean                foundIt = false;
  60.     
  61.     for (short i = 0; i < count; ++i) {
  62.         short len = *s;
  63.         if (*f == primaryFlavor) {
  64.             BlockMoveData (s, fName, (len > 31) ? 32 : len + 1);
  65.             foundIt = true;
  66.             break;
  67.         }
  68.         f = (FlavorType*) (s + s[0] + 1);
  69.         s = ((unsigned char*)f) + 4;
  70.     }
  71.     
  72.     if (!foundIt) {
  73.         fName [0] = 6;
  74.         fName [1] = '\'';
  75.         *((FlavorType*) &fName [2]) = primaryFlavor;
  76.         fName [6] = '\'';
  77.     }
  78. }
  79.  
  80. void CGenericThumbnail::Draw (Rect& r)
  81. {
  82.     TextFont (geneva);
  83.     TextSize (9);
  84.     
  85.     MoveTo (r.left, r.bottom - 4);
  86.     DrawString (fName);
  87. }
  88.  
  89. CGenericThumbnail::~CGenericThumbnail ()
  90. {
  91. }